package com.jlnk.androidfmc;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.jlnk.androidfmc.R;
import com.jlnk.androidfmc.presenter.BuyerHomePresenter;
import com.jlnk.androidfmc.presenter.BuyerHomePresenterImpl;
import com.jlnk.androidfmc.view.BuyerHomeView;

public class BuyerHomeActivity extends AppCompatActivity implements BuyerHomeView {
    private FrameLayout fragmentContainer;
    private BuyerHomePresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.buyer_header_view);

        fragmentContainer = findViewById(R.id.fragment_container);

        // 初始化Presenter
        presenter = new BuyerHomePresenterImpl(this);

        // 初始化加载推荐Fragment
        presenter.onCategoryClicked(0);

        // 设置选项点击事件
        setListeners();
    }

    private void setListeners() {
        findViewById(R.id.tv_recommend).setOnClickListener(view -> presenter.onCategoryClicked(0));
        findViewById(R.id.tv_fruit_vegetables).setOnClickListener(view -> presenter.onCategoryClicked(1));
        findViewById(R.id.tv_grain_oil).setOnClickListener(view -> presenter.onCategoryClicked(2));
        findViewById(R.id.tv_farming_supplies).setOnClickListener(view -> presenter.onCategoryClicked(2)); // Assuming it's the same as GrainsOilFragment
    }

    @Override
    public void loadFragment(Fragment fragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }

    @Override
    public void setOnClickListener(View view) {
        // 如果需要，可以添加更多的逻辑
    }
}